package ruleta_wicket.ruleta_wicket;

import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.PropertyModel;

import domain.Player;

public class ChangeChipsPanel extends Panel {
	private Player player;
	
	public ChangeChipsPanel(String id, Player modelObject) {
		super(id);
		this.player = modelObject; 
		CompoundPropertyModel<Player> model = new CompoundPropertyModel<Player>(
				modelObject);
		
		Form form = new Form("form");
		
		addFields(form);
		addActions(form);
		
		this.add(form);
	}	
	
	private void addFields(Form form) {
		form.add(new TextField<Player>("Dinero", new PropertyModel<Player>(this.player, Player.MONEY)));
		form.add(new TextField<Player>("Fichas", new PropertyModel<Player>(this.player, Player.CHIPS)));
		form.add(new FeedbackPanel("feedbackPanel"));
	}

	
	private void addActions(Form form) {
		form.add(new Button("Aceptar") {
			@Override
			public void onSubmit() {
				ChangeChipsPanel.this.player.changeChips();
			}
			
		});

		form.add(new Button("Cancelar") {
			@Override
			public void onSubmit() {
				
			}
		});
	}
}
